<?php
/**
 * 基础Redis服务，分库
 * User: dxk
 * Date: 2020/07/15
 */
namespace App\Service;

use Illuminate\Redis\RedisManager;

class EasyRedis
{
    /**
     * 获取Redis实例
     * @param string $prefix 前缀
     * @return \Redis
     */
    public static function getRedis($prefix = '')
    {
        static $redis_client;
        if (isset($redis_client)) {
            return $redis_client;
        }
        $config = config('database.redis');
        if (!empty($prefix)) {
            $config['options']['prefix'] = $prefix;
        }
        $RedisManager = new RedisManager(app(), \Arr::pull($config, 'client', 'phpredis'), $config);
        return $redis_client = $RedisManager->connection('core')->client();
    }
}